#!/bin/bash

# first copy the source into another folder
cd ../.
if [ ! $1 ]; then
	echo ""
	echo "Usage:   package.ede <version>"
	echo ""
	echo "Example: package.ede 4.0"
	echo ""
	echo "Note:    The version supplied here will not alter"
	echo "         the coded version or build number."
	echo ""
	exit
else
	echo "** EDE packaging script **"
fi
if [ ! $2 ]; then
	ede="ede"
else
	ede=$2
fi
newede="ede-"$1
echo " - Copying from "$ede" to new dir: "$newede
cp -r $ede $newede

# remove extra python and .tmp files
echo " - Removing python compilation files"
rm -rf `find "./"$newede -name '*.pyc'`
rm -rf `find "./"$newede -name '*.pyo'`
echo " - Removing temp files"
rm -rf `find "./"$newede -name '*.tmp'`
rm -rf $newede/dist
rm -rf $newede/build
rm -rf $newede/*.tmproj
rm -rf $newede/*.xcodeproj

#remove svn files
echo " - Removing SVN files"
for i in $( ls -aR $newede | grep ".svn" );
do
	location=${#i}
	if [ ${i:$location-1} = ":" ]; then
		rm -Rf ${i:0:($location-1)}
		#echo "removing " ${i:0:($location-1)}
	fi
done

# remove unused pixmaps
echo " - Removing unused pixmaps"
rm -rf $newede/pixmaps/splash.png
rm -rf $newede/pixmaps/newsletter_module.ico
rm -rf $newede/pixmaps/web_module.ico
rm -rf $newede/pixmaps/email_module.ico
rm -rf $newede/pixmaps/survey_module.ico
rm -rf $newede/pixmaps/referral_module.ico
rm -rf $newede/pixmaps/binders_module.ico
rm -rf $newede/pixmaps/contacts_module.ico
rm -rf $newede/pixmaps/newsletter_service_icon.png
rm -rf $newede/pixmaps/web_service_icon.png
rm -rf $newede/pixmaps/email_service_icon.png
rm -rf $newede/pixmaps/survey_service_icon.png
rm -rf $newede/pixmaps/referral_service_icon.png

# remove custom list of files
echo " - Removing all other unnecessary files"
rm -rf $newede/template.dmg.bz2
rm -rf $newede/template.dmg
rm -rf $newede/buildapp
rm -rf $newede/clean
rm -rf $newede/buildexe.bat
rm -rf $newede/ede.exe.manifest
rm -rf $newede/ede.iss
rm -rf $newede/.DS_Store
rm -rf $newede/package.ede

#tar the files
tarfile=$newede".tgz"
echo " - Tarring the package into "$tarfile
tar -czf $tarfile $newede

#zip the files
zipfile=$newede".zip"
echo " - Zipping the package into "$zipfile
zip -rq $zipfile $newede

scp $tarfile root@peach:/var/www/peach.etelos.com/ede/.
scp $zipfile root@peach:/var/www/peach.etelos.com/ede/.
ssh root@peach "chmod ugo+r /var/www/peach.etelos.com/ede/*"
ssh root@peach "scp /var/www/peach.etelos.com/ede/$zipfile corp:/var/www/v3.etelos.com/ede4/$zipfile"
ssh root@peach "scp /var/www/peach.etelos.com/ede/$tarfile corp:/var/www/v3.etelos.com/ede4/$tarfile"
ssh root@peach "rm /var/www/peach.etelos.com/ede/$tarfile;rm /var/www/peach.etelos.com/ede/$zipfile"
echo "[ done ]"
